package com.xintonghua.bussiness.adapter;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xintonghua.base.adapter.BaseAdapter;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.bean.GoodsItemBeaan;
import com.xintonghua.bussiness.bean.RewardBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：wanxianyi
 * 时间：2018/4/25.
 * 包名：com.xintonghua.bussiness.adapter
 */

public class RecordAdapter extends BaseAdapter<GoodsItemBeaan, RecordAdapter.ViewHolder> {
    String name;

    public RecordAdapter(Activity mActivity, List<GoodsItemBeaan> list, String name) {
        super(mActivity, list);
        this.name = name;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.adapter_record, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        GoodsItemBeaan beaan = list.get(position);
        if (name.equals("进货")) {
            holder.tvRecordCount.setText("+" + beaan.getCount());
            holder.tvRecordPrice.setText("-" + beaan.getTotalPrice());
            holder.tvRecordPrice.setTextColor(ContextCompat.getColor(mActivity, R.color.green));
            holder.tvRecordName.setText(beaan.getGoodsName());
        } else {
            holder.tvRecordCount.setText("-" + beaan.getCount());
            holder.tvRecordPrice.setText("+" + beaan.getTotalPrice());
            holder.tvRecordPrice.setTextColor(ContextCompat.getColor(mActivity, R.color.red));
            holder.tvRecordName.setText(beaan.getName());
        }



    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_record_name)
        TextView tvRecordName;
        @BindView(R.id.tv_record_price)
        TextView tvRecordPrice;
        @BindView(R.id.tv_record_count)
        TextView tvRecordCount;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
